home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 002 / make / parsedir.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  10KB  |  473 lines

  1. #include <stdio.h>
  2. #include "make.h"
  3.  
  4. #ifdef VAXVMS
  5. #  include <rms.h>
  6. #endif
  7.  
  8. extern DATE bigbang;
  9. extern DATE endoftime;
  10.  
  11. char *printdate ();
  12.  
  13. /*
  14.  * Get a file's creation date.
  15.  *
  16.  * First try for a normal file, then library, then archive.
  17.  */
  18.  
  19. void getdate (f)
  20. FILENODE *f;
  21. {
  22.     extern int isonlibrary ();
  23.     extern int isanarchive ();
  24.     
  25.     DBUG_ENTER ("getdate");
  26.     if (f -> fdate == (DATE) NULL) {
  27.     if (filedate (f) != SUCCEED) {
  28.         if (isonlibrary (f) != SUCCEED) {
  29.         if (isanarchive (f) != SUCCEED) {
  30.             if ((f -> fflag & ROOTP) == 0) {
  31.             fprintf (stderr, "Can't get date for file '%s'\n",
  32.                 f -> fname);
  33.             f -> fdate = endoftime;
  34.             } else {
  35.             f -> fdate = bigbang;
  36.             }
  37.         }
  38.         }
  39.     }
  40.     }
  41.     DBUG_VOID_RETURN;
  42. }
  43.  
  44.  
  45. #ifdef VAXVMS
  46. /*
  47.  * filedate - return file's creation date (VAX/VMS only.)
  48.  * Returns -1 if file cannot be found, 0 if succesful.
  49.  */
  50. filedate (fnd)
  51. FILENODE *fnd;
  52. {
  53.     register unsigned *datetime;
  54.     static DATE adate ();
  55.     register struct FAB *fptr;
  56.     register struct XABDAT *dptr;
  57.  
  58.     fptr = Calloc (1, sizeof (struct FAB));    /* allocate FAB and XABDAT */
  59.     dptr = Calloc (1, sizeof (struct XABDAT));
  60.     if (fptr == NULL || dptr == NULL) {
  61.     allerr ();
  62.     }
  63.     *fptr = cc $ rms_fab;    /* initialize FAB and XABDAT */
  64.     *dptr = cc $ rms_xabdat;
  65.     fptr -> fab $ l_xab = (char *) dptr;/* FAB -> XABDAT */
  66.     fptr -> fab $ l_fna = fnd -> fname;/* setup filename */
  67.     fptr -> fab $ b_fns = strlen (fnd -> fname);
  68.     if (sys$open (fptr) != RMS$_NORMAL ||    /* open the file */
  69.     sys$display (fptr) != RMS$_NORMAL) {    /* get XABDAT info */
  70.     return (-1)
  71.     }
  72.     datetime = &(dptr -> xab$q_cdt);    /* record 64-bit date */
  73.     fnd -> fdate = adate (datetime[0], datetime[1]);
  74.     sys$close (fptr);        /* close the file */
  75.     free (dptr);        /* clean up and return */
  76.     free (fptr);
  77.     return (0);
  78. }
  79.  
  80. /*
  81.  * laterdt - compare two dates.
  82.  * Return -1, 0 or 1 if date1 < date2, date1 == date2, or date1 > date2
  83.  */
  84.  
  85. laterdt (date1, date2)
  86. DATE date1, date2;
  87. {
  88.     if (date1 -> ds_high > date2 -> ds_high ||
  89.     (date1 -> ds_high >= date2 -> ds_high &&
  90.     date1 -> ds_low > date2 -> ds_low)) {
  91.     return (1);
  92.     } else if (date1 -> ds_high == date2 -> ds_high &&
  93.         date1 -> ds_low == date2 -> ds_low)
  94.     return (0);
  95.     } else {
  96.     return (-1);
  97.     }
  98. }
  99.  
  100.  
  101. /*
  102.  * adate - allocate a date with the given time
  103.  */
  104.  
  105. DATE adate (time1, time2)
  106. unsigned time1;
  107. unsigned time2;
  108. {
  109.     auto DATE d;
  110.  
  111.     if ((d = (DATE) Calloc (1, sizeof (struct date_str))) == NULL) {
  112.     allerr ();
  113.     }
  114.     d -> ds_low = time1;
  115.     d -> ds_high = time2;
  116.     return (d);
  117. }
  118.  
  119. initrootdates ()
  120. {
  121.     bigbang = adate (0, 0);        /* init root dates */
  122.     endoftime = adate (~0, ~0);
  123. }
  124.  
  125. char *printdate (fdate)
  126. DATE fdate;
  127. {
  128.     static char *buffer[64];
  129.  
  130.     sprintf (buffer, "( %u, %u )",
  131.         (f -> fdate != NULL) ? (f -> fdate) -> ds_high : 0,
  132.         (f -> fdate != NULL) ? (f -> fdate) -> ds_low : 0);
  133.     return (buffer);
  134. }
  135. #endif
  136.  
  137.  
  138. #ifdef MSDOS
  139.  
  140. /*
  141.  * filedate - return file's creation date (MSDOS only.)
  142.  * Returns -1 if file cannot be found, 0 if successful
  143.  */
  144.  
  145. filedate (fnd)
  146. FILENODE *fnd;
  147. {
  148.     extern DATE osdate ();
  149.     auto DATE newdate;
  150.     auto int success;
  151.  
  152.     success = FAILURE;
  153.     newdate = osdate (fnd -> fname, &success);
  154.     if (success == FAILURE) {
  155.     return (FAILURE);
  156.     }
  157.     fnd -> fdate = newdate;
  158.     fnd -> fflag |= EXTRACT;    /* don't extract this file again */
  159.     return (SUCCEED);
  160. }
  161.  
  162. /*
  163.  * laterdt - compare two dates.
  164.  * Return -1, 0 or 1 if date1 < date2, date1 == date2, or date1 > date2
  165.  */
  166.  
  167. laterdt (date1, date2)
  168. DATE date1;
  169. DATE date2;
  170. {
  171.     if (date1 -> ft_year > date2 -> ft_year) {
  172.     return (1);
  173.     }
  174.     if (date1 -> ft_year < date2 -> ft_year) {
  175.     return (-1);
  176.     }
  177.     /* years are equal */
  178.     if (date1 -> ft_month > date2 -> ft_month) {
  179.     return (1);
  180.     }
  181.     if (date1 -> ft_month < date2 -> ft_month) {
  182.     return (-1);
  183.     }
  184.     /* months are equal */
  185.     if (date1 -> ft_day > date2 -> ft_day) {
  186.     return (1);
  187.     }
  188.     if (date1 -> ft_day < date2 -> ft_day) {
  189.     return (-1);
  190.     }
  191.     /* days are equal */
  192.     if (date1 -> ft_hour > date2 -> ft_hour) {
  193.     return (1);
  194.     }
  195.     if (date1 -> ft_hour < date2 -> ft_hour) {
  196.     return (-1);
  197.     }
  198.     /* hours are equal */
  199.     if (date1 -> ft_min > date2 -> ft_min) {
  200.     return (1);
  201.     }
  202.     if (date1 -> ft_min < date2 -> ft_min) {
  203.     return (-1);
  204.     }
  205.     /* minutes are equal */
  206.     if (date1 -> ft_tsec > date2 -> ft_tsec) {
  207.     return (1);
  208.     }
  209.     if (date1 -> ft_tsec < date2 -> ft_tsec) {
  210.     return (-1);
  211.     }
  212.     /* everything is equal */
  213.     return (0);
  214. }
  215.  
  216. /*
  217.  * adate - allocate a date struct to be filled out later.
  218.  */
  219.  
  220. DATE adate ()
  221. {
  222.     auto DATE d;
  223.  
  224.     if ((d = (DATE) Calloc (1, sizeof (struct ftime))) == (DATE) NULL) {
  225.     allerr ();
  226.     }
  227.     return (d);
  228. }
  229.  
  230. initrootdates ()
  231. {        /* init root dates */
  232.     bigbang = adate ();
  233.     bigbang -> ft_tsec = 0;
  234.     bigbang -> ft_min = 0;
  235.     bigbang -> ft_hour = 0;
  236.     bigbang -> ft_day = 1;
  237.     bigbang -> ft_month = 1;
  238.     bigbang -> ft_year = 0;
  239.     endoftime = adate ();
  240.     endoftime- > ft_tsec = 29;
  241.     endoftime- > ft_min = 59;
  242.     endoftime- > ft_hour = 23;
  243.     endoftime- > ft_day = 31;
  244.     endoftime- > ft_month = 11;
  245.     endoftime- > ft_year = 127;
  246. }
  247.  
  248. char *printdate (fdate)
  249. DATE fdate;
  250. {
  251.     auto char buf[10];
  252.  
  253. #ifdef NOTYETCONVERTED
  254.     fputs ("( ", stdout);
  255.     itoa (fdate- > ft_hour, buf);
  256.     fputs (buf, stdout);
  257.     fputc (':', stdout);
  258.     itoa (fdate- > ft_min, buf);
  259.     fputs (buf, stdout);
  260.     fputc (':', stdout);
  261.     itoa (fdate- > ft_tsec, buf);
  262.     fputs (buf, stdout);
  263.     fputs (", ", stdout);
  264.     itoa (fdate- > ft_month, buf);
  265.     fputs (buf, stdout);
  266.     fputc ('-', stdout);
  267.     itoa (fdate- > ft_day, buf);
  268.     fputs (buf, stdout);
  269.     fputc ('-', stdout);
  270.     itoa (fdate- > ft_year + 80, buf);
  271.     fputs (buf, stdout);
  272.     puts (" )");
  273. #else
  274.     return ("<not available>");
  275. #endif
  276. }
  277. #endif
  278.  
  279. #ifdef unix
  280.  
  281. /*
  282.  * filedate - return file's creation date (unix only.)
  283.  * Returns -1 if file cannot be found, 0 if successful
  284.  */
  285.  
  286. filedate (fnd)
  287. FILENODE *fnd;
  288. {
  289.     extern DATE osdate ();
  290.     auto DATE newdate;
  291.     auto int success = FAILURE;
  292.  
  293.     DBUG_ENTER ("filedate");
  294.     DBUG_3 ("date", "find date for '%s'", fnd -> fname);
  295.     newdate = osdate (fnd -> fname, &success);
  296.     DBUG_3 ("date", "has date %s", printdate (newdate));
  297.     if (success != FAILURE) {
  298.     fnd -> fdate = newdate;
  299.     fnd -> fflag |= EXTRACT;    /* do not extract this file again */
  300.     success = SUCCEED;
  301.     }
  302.     DBUG_RETURN (success);
  303. }
  304.  
  305. /*
  306.  * laterdt - compare two dates.
  307.  * Return -1, 0 or 1 if date1 < date2, date1 == date2, or date1 > date2
  308.  */
  309.  
  310. laterdt (date1, date2)
  311. DATE date1;
  312. DATE date2;
  313. {
  314.     int result;
  315.     
  316.     DBUG_ENTER ("laterdt");
  317.     DBUG_4 ("dcmp", "compare %lu vs %lu", *date1, *date2);
  318.     if (*date1 > *date2) {
  319.     result = 1;
  320.     } else if (*date1 < *date2) {
  321.     result = -1;
  322.     } else {
  323.     result = 0;
  324.     }
  325.     DBUG_3 ("dcmp", "result is %d", result);
  326.     DBUG_RETURN (result);
  327. }
  328.  
  329. /*
  330.  * adate - allocate a date struct to be filled out later.
  331.  */
  332.  
  333. DATE adate ()
  334. {
  335.     auto DATE d;
  336.  
  337.     DBUG_ENTER ("adate");
  338.     if ((d = (DATE) Calloc (1, sizeof (long))) == (DATE) NULL) {
  339.     allerr ();
  340.     }
  341.     DBUG_RETURN (d);
  342. }
  343.  
  344. void initrootdates ()
  345. {        /* init root dates */
  346.     DBUG_ENTER ("initrootdates");
  347.     bigbang = adate ();
  348.     *bigbang = 0;
  349.     endoftime = adate ();
  350.     *endoftime = ~0;
  351.     DBUG_VOID_RETURN;
  352. }
  353.  
  354. char *printdate (fdate)
  355. DATE fdate;
  356. {
  357.     static char datebuf[64];
  358.  
  359.     if (fdate == NULL) {
  360.     sprintf (datebuf, "<null date>");
  361.     } else {
  362.     sprintf (datebuf, "%lu", *fdate);
  363.     }
  364.     return (datebuf);
  365. }
  366.  
  367. #endif
  368.  
  369. #ifdef AMIGA
  370.  
  371. /*
  372.  * filedate - return file's creation date (Amiga only.)
  373.  * Returns -1 if file cannot be found, 0 if successful
  374.  */
  375.  
  376. filedate (fnd)
  377. FILENODE *fnd;
  378. {
  379.     extern DATE osdate ();
  380.     auto DATE newdate;
  381.     auto int success = FAILURE;
  382.  
  383.     DBUG_ENTER ("filedate");
  384.     newdate = osdate (fnd -> fname, &success);
  385.     if (success == SUCCEED) {
  386.     DBUG_3 ("fdate", "found date for '%s'", fnd -> fname);
  387.     fnd -> fdate = newdate;
  388.     fnd -> fflag |= EXTRACT;    /* don't extract this file again */
  389.     }
  390.     DBUG_RETURN (success);
  391. }
  392.  
  393. /*
  394.  * laterdt - compare two dates.
  395.  * Return -1, 0 or 1 if date1 < date2, date1 == date2, or date1 > date2
  396.  */
  397.  
  398. int laterdt (date1, date2)
  399. DATE date1;
  400. DATE date2;
  401. {
  402.     register int result;
  403.     
  404.     DBUG_ENTER ("laterdt");
  405.     DBUG_3 ("dcmp", "compare date1 %s", printdate (date1));
  406.     DBUG_3 ("dcmp", "with    date2 %s", printdate (date2));
  407.     if (date1 -> ds_Days > date2 -> ds_Days) {
  408.     result = 1;
  409.     } else if (date1 -> ds_Days < date2 -> ds_Days) {
  410.     result = -1;
  411.     } else {
  412.     if (date1 -> ds_Minute > date2 -> ds_Minute) {
  413.         result = 1;
  414.     } else if (date1 -> ds_Minute < date2 -> ds_Minute) {
  415.         result = -1;
  416.     } else {
  417.         if (date1 -> ds_Tick > date2 -> ds_Tick) {
  418.         result = 1;
  419.         } if (date1 -> ds_Tick < date2 -> ds_Tick) {
  420.         result = -1;
  421.         } else {
  422.         result = 0;
  423.         }
  424.     }
  425.     }
  426.     DBUG_3 ("dcmp", "result is %d", result);
  427.     DBUG_RETURN (result);
  428. }
  429.  
  430. /*
  431.  * adate - allocate a date struct to be filled out later.
  432.  */
  433.  
  434. DATE adate ()
  435. {
  436.     auto DATE d;
  437.  
  438.     DBUG_ENTER ("adate");
  439.     if ((d = (DATE) Calloc (1, sizeof (struct DateStamp))) == (DATE) NULL) {
  440.     allerr ();
  441.     }
  442.     DBUG_RETURN (d);
  443. }
  444.  
  445. void initrootdates ()
  446. {        /* init root dates */
  447.     DBUG_ENTER ("initrootdates");
  448.     bigbang = adate ();
  449.     bigbang -> ds_Days = 0;
  450.     bigbang -> ds_Minute = 0;
  451.     bigbang -> ds_Tick = 0;
  452.     endoftime = adate ();
  453.     endoftime -> ds_Days = ~0;
  454.     endoftime -> ds_Minute = ~0;
  455.     endoftime -> ds_Tick = ~0;
  456.     DBUG_VOID_RETURN;
  457. }
  458.  
  459. char *printdate (fdate)
  460. DATE fdate;
  461. {
  462.     static char datebuf[64];
  463.  
  464.     if (fdate == NULL) {
  465.     sprintf (datebuf, "<null date>");
  466.     } else {
  467.     sprintf (datebuf, "days:%lu min:%lu ticks:%lu", fdate -> ds_Days,
  468.                 fdate -> ds_Minute, fdate -> ds_Tick);
  469.     }
  470.     return (datebuf);
  471. }
  472. #endif
  473.